package com.rasou.consumer;

import com.rasou.service.HelloService;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class MyConsumer {

    private final static Logger log = LoggerFactory.getLogger(MyConsumer.class);
    public static void main(String[] args) throws Exception {
        ReferenceConfig<HelloService> reference = new ReferenceConfig<>();
        reference.setApplication(new ApplicationConfig("dubbo-consumer"));
        reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
        reference.setInterface(HelloService.class);

        Runnable runnable = () -> {
            HelloService service = reference.get();
            System.out.println(service.hello());
        };
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();

        TimeUnit.SECONDS.sleep(10);
        try {
            System.out.println("启动错误");
        } catch (Exception e) {
            log.info("error:",e);
        }
    }
}
